package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysRole;
import com.pine.dao.pineframework.mapper.SysRoleMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysRoleBo;
import com.pine.manager.pineframework.convertors.SysRoleConvertor;
import com.pine.manager.pineframework.query.SysRoleQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 角色表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysRoleManager extends BaseManager<SysRoleMapper, SysRole, Long, SysRoleBo, SysRoleQuery, SysRoleConvertor> {

    @Resource
    private SysRoleConvertor sysRoleConvertor;

    @Override
    public LambdaQueryWrapper<SysRole> encapsulateQueryWrapper(SysRoleQuery query) {
        LambdaQueryWrapper<SysRole> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysRole::getName, query.getName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCode()), SysRole::getCode, query.getCode());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getSort()), SysRole::getSort, query.getSort());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getStatus()), SysRole::getStatus, query.getStatus());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getDataScope()), SysRole::getDataScope, query.getDataScope());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SysRole::getCreateUserId, query.getCreateUserId());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysRole::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysRole::getUpdateTime, query.getUpdateTimeEnd());

        // 排序
        queryWrapper.orderByAsc(SysRole::getSort);
        return queryWrapper;
    }
}
